package com.project.interceptor;

import com.project.bean.UserBean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户拦截器
 */
@Component
public class CustomInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //得到登录信息
        UserBean user = (UserBean)request.getSession().getAttribute("loginUser");
        if (user != null && "顾客".equals(user.getLevel())){
            return true;
        }
        response.sendRedirect("/login.html?loginError=noCustom");
        return false;
    }
}
